
import 'osc_notice.dart';

class OscPostListEntity {
	List<OscPost> postList;
	OscNotice notice;

	OscPostListEntity({this.postList, this.notice});

	OscPostListEntity.fromJson(Map<String, dynamic> json) {
		if (json['post_list'] != null) {
			postList = new List<OscPost>();(json['post_list'] as List).forEach((v) { postList.add(new OscPost.fromJson(v)); });
		}
		notice = json['notice'] != null ? new OscNotice.fromJson(json['notice']) : null;
	}

	Map<String, dynamic> toJson() {
		final Map<String, dynamic> data = new Map<String, dynamic>();
		if (this.postList != null) {
      data['post_list'] =  this.postList.map((v) => v.toJson()).toList();
    }
		if (this.notice != null) {
      data['notice'] = this.notice.toJson();
    }
		return data;
	}
}

class OscPost {
	int answerCount;//回复数
	Answer answer;//最后回帖
	String author;//发帖人
	int id;//帖子ID
	int viewCount;//浏览数
	String title;//帖子标题
	String portrait;//发帖人用户头像地址
	int authorId;//发布者ID
	String pubDate;//发布时间

	OscPost({this.answerCount, this.answer, this.author, this.id, this.viewCount, this.title, this.portrait, this.authorId, this.pubDate});

	OscPost.fromJson(Map<String, dynamic> json) {
		answerCount = json['answerCount'];
		dynamic answerValue = json['answer'];
		if(answerValue != null && (answerValue.toString().compareTo("") != 0)){
      answer = new Answer.fromJson(json['answer']);
		}
//		answer = json['answer'] != null ? new Answer.fromJson(json['answer']) : null;
		author = json['author'];
		id = json['id'];
		viewCount = json['viewCount'];
		title = json['title'];
		portrait = json['portrait'];
		authorId = json['authorid'];
		pubDate = json['pubDate'];
	}

	Map<String, dynamic> toJson() {
		final Map<String, dynamic> data = new Map<String, dynamic>();
		data['answerCount'] = this.answerCount;
		if (this.answer != null) {
      data['answer'] = this.answer.toJson();
    }
		data['author'] = this.author;
		data['id'] = this.id;
		data['viewCount'] = this.viewCount;
		data['title'] = this.title;
		data['portrait'] = this.portrait;
		data['authorid'] = this.authorId;
		data['pubDate'] = this.pubDate;
		return data;
	}
}

class Answer {
	String name;//最后回帖用户
	String time;//最后回帖时间

	Answer({this.name, this.time});

	Answer.fromJson(Map<String, dynamic> json) {
		name = json['name'];
		time = json['time'];
	}

	Map<String, dynamic> toJson() {
		final Map<String, dynamic> data = new Map<String, dynamic>();
		data['name'] = this.name;
		data['time'] = this.time;
		return data;
	}
}
